Skip to content

Conversation

xezon
Copy link

@xezon xezon commented Sep 25, 2025

This change simplifies the texture reduction code. It was way too convoluted.

TODO

  • Replicate in Generals

@xezon xezon added Minor Severity: Minor < Major < Critical < Blocker Refactor Edits the code with insignificant behavior changes, is never user facing labels Sep 25, 2025
Copy link

@Skyaero42 Skyaero42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@xezon xezon force-pushed the xezon/gamelod-4-refactor-texture-reduction branch from fb42749 to 8b23655 Compare October 12, 2025 08:54
@xezon
Copy link
Author

xezon commented Oct 12, 2025

Replicated with conflicts

D:\Projects\TheSuperHackers\GeneralsGameCode>FOR /F "delims=" %b IN ('git merge-base --fork-point main') DO git diff %b  1>changes.patch

D:\Projects\TheSuperHackers\GeneralsGameCode>git diff 5155aeafec55bb6800fb430c47eb08821b8ebee4  1>changes.patch

D:\Projects\TheSuperHackers\GeneralsGameCode>git apply -p2 --directory=Generals --reject --whitespace=fix changes.patch
changes.patch:90: space before tab in indent.
                //-------------------------------------------------------------------------------------------------
changes.patch:91: space before tab in indent.
                // Texture resolution slider
changes.patch:97: space before tab in indent.
                                val = 2 - GadgetSliderGetPosition(sliderTextureResolution);
Checking patch Generals/Code/GameEngine/Include/Common/GameLOD.h...
Hunk #1 succeeded at 176 (offset -1 lines).
error: while searching for:
        Real m_floatBenchIndex;
        Real m_memBenchIndex;
        Real m_compositeBenchIndex;
        Int m_currentTextureReduction;
        Int m_reallyLowMHz;
};


error: patch failed: Generals/Code/GameEngine/Include/Common/GameLOD.h:230
Checking patch Generals/Code/GameEngine/Include/GameClient/GameClient.h...
Hunk #1 succeeded at 138 (offset -5 lines).
Checking patch Generals/Code/GameEngine/Source/Common/GameLOD.cpp...
Hunk #1 succeeded at 227 (offset -2 lines).
Hunk #2 succeeded at 579 (offset -5 lines).
Hunk #3 succeeded at 616 (offset -6 lines).
Checking patch Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp...
Hunk #2 succeeded at 1114 (offset -51 lines).
Hunk #3 succeeded at 1853 (offset -67 lines).
Checking patch Generals/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp...
error: while searching for:
#include "GameNetwork/GameSpyOverlay.h"
#include "GameNetwork/GameSpy/BuddyThread.h"




#define dont_ALLOW_ALT_F4

error: patch failed: Generals/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp:88
Hunk #2 succeeded at 3785 (offset -394 lines).
Hunk #3 succeeded at 3796 (offset -394 lines).
Checking patch Generals/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DGameClient.h...
error: while searching for:

        //---------------------------------------------------------------------------
        virtual void setTeamColor( Int red, Int green, Int blue );  ///< @todo superhack for demo, remove!!!
        virtual void adjustLOD( Int adj ); ///< @todo hack for evaluation, remove.
        virtual void notifyTerrainObjectMoved(Object *obj);

protected:

error: patch failed: Generals/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DGameClient.h:92
Checking patch Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/TerrainTex.cpp...
Hunk #1 succeeded at 187 (offset -8 lines).
Checking patch Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp...
error: while searching for:
                        TheGameLODManager->setStaticLODLevel(TheGameLODManager->getRecommendedStaticLODLevel());
                }
                else
                {       //Static LOD level was applied during GameLOD manager init except for texture reduction
                        //which needs to be applied here.
                        Int txtReduction=TheWritableGlobalData->m_textureReductionFactor;
                        if (txtReduction > 0)
                        {               WW3D::Set_Texture_Reduction(txtReduction,32);
                                        //Tell LOD manager that texture reduction was applied.
                                        TheGameLODManager->setCurrentTextureReduction(txtReduction);
                        }
                }

                if (TheGlobalData->m_displayGamma != 1.0f)

error: patch failed: Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp:795
Checking patch Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DGameClient.cpp...
error: while searching for:
}

//-------------------------------------------------------------------------------------------------
/** temporary entry point for adjusting LOD for development testing. */
//-------------------------------------------------------------------------------------------------
void W3DGameClient::adjustLOD( Int adj )
{
        if (TheGlobalData == NULL)
                return;

        TheWritableGlobalData->m_textureReductionFactor += adj;

        if (TheWritableGlobalData->m_textureReductionFactor > 4)
                TheWritableGlobalData->m_textureReductionFactor = 4;    //16x less resolution is probably enough.
        if (TheWritableGlobalData->m_textureReductionFactor < 0)
                TheWritableGlobalData->m_textureReductionFactor = 0;

        if (WW3D::Get_Texture_Reduction() != TheWritableGlobalData->m_textureReductionFactor)
        {       WW3D::Set_Texture_Reduction(TheWritableGlobalData->m_textureReductionFactor,32);
                TheGameLODManager->setCurrentTextureReduction(TheWritableGlobalData->m_textureReductionFactor);
                if( TheTerrainRenderObject )
                        TheTerrainRenderObject->setTextureLOD( TheWritableGlobalData->m_textureReductionFactor );
        }

}

//-------------------------------------------------------------------------------------------------

error: patch failed: Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DGameClient.cpp:196
Checking patch Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp...
error: while searching for:
        DX8_ErrorCode(surface_level->UnlockRect());
        surface_level->Release();
        DX8_ErrorCode(D3DXFilterTexture(Peek_D3D_Texture(), NULL, (UINT)0, D3DX_FILTER_BOX));
        if (TheWritableGlobalData->m_textureReductionFactor) {
                DX8_ErrorCode(Peek_D3D_Texture()->SetLOD((DWORD)TheWritableGlobalData->m_textureReductionFactor));
        }
        return(surface_desc.Height);
}

error: patch failed: Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp:189
Checking patch Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/WorldHeightMap.cpp...
error: while searching for:

TerrainTextureClass *WorldHeightMap::getFlatTexture(Int xCell, Int yCell, Int cellWidth, Int pixelsPerCell)
{
        if (TheWritableGlobalData->m_textureReductionFactor) {
                if (TheWritableGlobalData->m_textureReductionFactor>1) {
                        pixelsPerCell /= 4;
                } else {
                        pixelsPerCell /= 2;

error: patch failed: Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/WorldHeightMap.cpp:2214
Applying patch Generals/Code/GameEngine/Include/Common/GameLOD.h with 1 reject...
Hunk #1 applied cleanly.
Rejected hunk #2.
Applied patch Generals/Code/GameEngine/Include/GameClient/GameClient.h cleanly.
Applied patch Generals/Code/GameEngine/Source/Common/GameLOD.cpp cleanly.
Applied patch Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp cleanly.
Applying patch Generals/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp with 1 reject...
Rejected hunk #1.
Hunk #2 applied cleanly.
Hunk #3 applied cleanly.
Applying patch Generals/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DGameClient.h with 1 reject...
Rejected hunk #1.
Applied patch Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/TerrainTex.cpp cleanly.
Applying patch Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplay.cpp with 1 reject...
Rejected hunk #1.
Applying patch Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DGameClient.cpp with 1 reject...
Rejected hunk #1.
Applying patch Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DTreeBuffer.cpp with 1 reject...
Rejected hunk #1.
Applying patch Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/WorldHeightMap.cpp with 1 reject...
Rejected hunk #1.

@xezon
Copy link
Author

xezon commented Oct 12, 2025

Tested in Generals and it looked fine.

@xezon xezon merged commit ebe28dc into TheSuperHackers:main Oct 12, 2025
18 checks passed
@xezon xezon deleted the xezon/gamelod-4-refactor-texture-reduction branch October 12, 2025 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Minor Severity: Minor < Major < Critical < Blocker Refactor Edits the code with insignificant behavior changes, is never user facing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants